// locutor
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id$
package locutor.model.parsing.grgen

import scala.util.parsing.combinator._
import scala.util.parsing.combinator.syntactical._

/** 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
private [grgen] trait BaseParser extends StdTokenParsers with ImplicitConversions {
  
  def text        = (ident | string)
  
  def ident_decl  = ident ~ opt(annotation) ^^ {
    case id ~ annos => Ident(id, None, annos)
  }
  
  def annotation  = ("[" ~> ident) ~ ("=" ~> constant) ~ ((("," ~> ident) ~ ("=" ~> constant))*) <~ "]" ^^ {
    case key ~ value ~ rest => ((key, value)) :: (rest map {case k ~ v => (k, v)})
  }
  
  def constant    = numeric | string | "true" | "false" | "null"

  def primitives  = "boolean" | "int" | "float" | "double" | "string" | "object"
  
  def string      = accept("string",  {case lexical.StringLit(n) => n})
  
  def numeric     = accept("numeric", {case lexical.NumericLit(n) => n})

}
